
$(function () {
    var _getParam = function (obj, param) {
        return obj[param] || '';
    };
    var picker = new mui.PopPicker({ layer: 3 });
    picker.setData(cityData)
    $(document).on('tap', '#showCityPicker', () => {
        picker.show(function (items) {
            console.log("你选择的城市是:" + _getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text'))
            $('#showCityPicker').val(_getParam(items[0], 'text') + " " + _getParam(items[1], 'text') + " " + _getParam(items[2], 'text'));
        })
    })
    //添加收货地址
    $('#addAddr').on('tap', () => {
        let addrUser = $('#addrUser').val()
        let eNumber = $('#eNumber').val()
        let showCityPicker = $('#showCityPicker').val()
        let detail = $('#detail').val()
        if (!addrUser) {
            mui.toast('收获人不能为空!')
            return
        }
        if (!eNumber) {
            mui.toast('邮编不能为空!')
            return
        }
        if (!showCityPicker) {
            mui.toast('收货地址不能为空!')
            return
        }
        if (!detail) {
            mui.toast('详细地址不能为空!')
            return
        }
        $.ajax({
            type: 'POST',
            url: '/address/addAddress',
            data: {
                recipients: addrUser,
                postcode: eNumber,
                address: showCityPicker,
                addressDetail: detail
            },
            success: (result) => {
                if (result) {
                    mui.alert('添加成功!', () => {
                        viewApi.back();//返回上一个视图
                        getAddresses()
                    });
                    return
                } else {
                    mui.alert('无法访问服务,请联系wx:13278865643');
                }
            }
        })
    })


})

